/* Copyright (C) 2008 Robin Debreuil -- Released under the BSD License */

#define IS_TRIAL_FALSE

using System;
using System.Collections.Generic;
using System.Text;

using System.IO;
using ms = System.Drawing;
using ms2 = System.Drawing.Drawing2D;
using DDW.Vex;
using Microsoft.Win32;

namespace DDW.Xaml
{
	public abstract class XamlRenderer
	{
		public bool BlendCompatible = true;

		protected XamlWriter xw;
		protected VexObject v;
		public StringBuilder Log;
		protected Stack<Instance> timelineStack = new Stack<Instance>();

		//XamlWriter tlw; // timeline objects
		public const string symbolPrefix = "def_";
		public const string timelinePrefix = "tl_";
		public const string instancePrefix = "inst_";
		public const string visualBrushPrefix = "vb_";
		public const string imageBrushPrefix = "img_";
		public const string timelineSeparator = "_";
		protected string instName;
		protected Dictionary<string, string> imageBrushes = new Dictionary<string, string>();
		protected Dictionary<string, Image> images = new Dictionary<string, Image>();

		protected bool isFirstMask = false; // these will need to go to a stack on timelines
		protected bool isMasking = false; // these will need to go to a stack on timelines
		protected uint curMaskDepth = 0;
		protected uint finalMaskDepth = 0;

		public static List<string> BuiltInFonts;

		protected bool isWatermarking;
		public bool Watermarking { get { return isWatermarking; } set { isWatermarking = value; } }
		protected string headerComment = @"This file was generated by theConverted - SWF to XAML Edition, version 1055. For more info, see http://theconverted.ca   ";
		protected string trialComment = @"This file was generated with the unregistered trial version.";

		public void GenerateXaml(VexObject v)
		{
			string xamlFileName;
			GenerateXaml(v, out xamlFileName);
		}
		public abstract void GenerateXaml(VexObject v, out string xamlFileName);
		public abstract void GenerateXamlPart(VexObject v, IDefinition def, out string xamlFileName);
		public abstract void WriteTimelineDefiniton(Timeline timeline, bool isRoot);
		//public abstract void WriteStoryboards(List<IInstance> instances, bool isRoot);
		//public abstract void WriteStoryboard(IDefinition s, Instance inst);
		//public abstract void WriteVisibility(Instance inst);
		public abstract void WriteSoundInstance(SoundInstance sound);
		public abstract void WriteInstance(IDefinition s, Instance inst);
		public abstract void WriteSymbolDefinition(Symbol symbol);

		protected string GetDefinitionName(IDefinition def)
		{
			string result;
			if (def.Name != null && def.Name != "")
			{
				result = def.Name;
			}
			else
			{
				result = symbolPrefix + def.Id.ToString();
			}
			return result;
		}
		protected string GetInstanceName(IInstance inst)
		{
			string result = "rt";
			if (timelineStack.Count > 0)
			{
				Instance[] tls = timelineStack.ToArray();
				for (int i = 0; i < tls.Length; i++)
				{
					result += timelineSeparator + tls[i].InstanceID;
				}
			}
			result += timelineSeparator + inst.InstanceID;

			return result;
		}

		public void WriteInstances(List<IInstance> instances, bool isRoot)
		{
			// write timeline instances
			for (int i = 0; i < instances.Count; i++)
			{
				if (instances[i] == null)
				{
					continue;
				}
				instName = GetInstanceName(instances[i]);//i + timelineSeparator + timelineStack.Peek().InstanceID;
				if (instances[i] is Instance)
				{
					Instance instance = (Instance)instances[i];
					if (!v.Definitions.ContainsKey(instance.DefinitionId))
					{
						continue;
					}
					IDefinition def = v.Definitions[instance.DefinitionId];
					if (def == null)
					{
						continue;
					}
					if (instance.IsMask)
					{
						isMasking = true;
						if(!isFirstMask)
						{
							isFirstMask = true;
							curMaskDepth = instance.Depth;
							finalMaskDepth = instance.MaskDepth;
							WriteOpenMask(def, instance);
						}
					}
					else if (isMasking)
					{
						if (isFirstMask)
						{
							isFirstMask = false;
							//xw.WriteEndElement();
						}
						if (instance.Depth >= finalMaskDepth)
						{
							xw.WriteEndElement();
							isMasking = false;
						}
					}

					if (!instance.IsMask)
					{
						if (def is Timeline)
						{
							timelineStack.Push(instance);
							WriteTimelineDefiniton((Timeline)def, false);
							timelineStack.Pop();
							//WriteTimelineInstance((Timeline)def, instance);
						}
						else if (def is Text)
						{
							WriteTextBlock((Text)def, instance);
						}
						else
						{
							WriteInstance(def, instance);
						}
					}
					else
					{
					}
				}
				else if (instances[i] is SoundInstance)
				{
					SoundInstance sound = (SoundInstance)instances[i];
					WriteSoundInstance(sound);
				}
			}
			if (isMasking)
			{
				isMasking = false;
				xw.WriteEndElement();
			}

			// write watermark
			if (isWatermarking && isRoot)
			{
				WriteWatermarkInstances();
			}
		}
		public void WriteSoundStoryboard(SoundInstance sound)
		{
			// <MediaTimeline Source="stevie.mp3" Storyboard.TargetName="stevieSound" BeginTime="0:0:1"/>

			xw.WriteStartElement("MediaTimeline");

			xw.WriteStartAttribute("Source");
			xw.WriteValue(sound.Path);
			xw.WriteEndAttribute();

			xw.WriteStartAttribute("Storyboard.TargetName");
			xw.WriteValue(VexObject.SoundPrefix + sound.DefinitionId);
			xw.WriteEndAttribute();

			xw.WriteStartAttribute("BeginTime"); 
			xw.WriteMilliseconds(sound.StartTime);
			xw.WriteEndAttribute();

			xw.WriteEndElement();

		}
		public virtual void WriteTextBlock(Text txt, Instance inst)
		{

			// <Block FontFamily=
			//   FontSize="40"
			//   FontFamily="Georgia"
			//   FontStyle="Italic" FontWeight="Bold"
			//   Canvas.Top="20" Canvas.Left="20"
			//	 Foreground="Red">
			//  test
			// </Block>

			xw.WriteStartElement("Canvas");

			if (inst != null)
			{
				string name = (inst.Name != null && inst.Name != "") ? inst.Name : instancePrefix + instName;
				xw.WriteStartAttribute("x:Name");
				xw.WriteValue(instancePrefix + instName);
				xw.WriteEndAttribute();
			}

			// ***** Can't use spans as that loses centering

			if(txt.TextRuns.Count == 0)
			{
				// todo: need to add edit text box attributes to Text tag, or have EditText tag
				//WriteTextAttributes(tr);
			}
			//else if (txt.TextRuns.Count == 1)
			//{
			//    TextRun tr = txt.TextRuns[0];

			//    xw.WriteStartElement("TextBlock");
			//    xw.WriteAttributeString("Canvas.Left", tr.Left);
			//    xw.WriteAttributeString("Canvas.Top", tr.Top);

			//    WriteTextAttributes(tr);
			//    xw.WriteValue(tr.Text);

			//    xw.WriteEndElement();
			//}
			else // multi text runs
			{
				xw.WriteStartElement("TextBlock");
				for (int i = 0; i < txt.TextRuns.Count; i++)
				{
					TextRun tr = txt.TextRuns[i];

					if (i > 0 && tr.isContinuous)
					{
						xw.WriteStartElement("Span");

						WriteTextAttributes(tr);
						xw.WriteValue(tr.Text);

						xw.WriteEndElement();
					}
					else
					{
						if (i > 0)
						{
							xw.WriteEndElement();
							xw.WriteStartElement("TextBlock");
						}
						xw.WriteAttributeString("Canvas.Left", tr.Left.ToString());
						xw.WriteAttributeString("Canvas.Top", tr.Top.ToString());

						WriteTextAttributes(tr);
						xw.WriteValue(tr.Text);

					}
					//if (tr.isMultiline)
					//{
					//    xw.WriteStartElement("LineBreak");
					//    xw.WriteEndElement();
					//}
				}
				xw.WriteEndElement();
			}


			xw.WriteEndElement(); // Canvas

		}
		protected void WriteTextAttributes(TextRun tr)
		{
			xw.WriteStartAttribute("FontSize");
			xw.WriteValue(tr.FontSize);
			xw.WriteEndAttribute();

			// decide weather to use ttf resource or not
			if (BuiltInFonts.Contains(tr.FontName))
			{
				xw.WriteStartAttribute("FontFamily");
				xw.WriteValue(tr.FontName);
				xw.WriteEndAttribute();
			}
			else
			{
				if (FontUtil.GetInstance().FontMap.ContainsKey(tr.FontName))
				{
					// FontFamily="Resources/#Calligrapher"
					
					xw.WriteStartAttribute("FontFamily");
					xw.WriteValue(v.ResourceFolder + @"/#" +  tr.FontName);
					xw.WriteEndAttribute();
					Utils.CopyFontToResources(tr.FontName, v.ResourceFolder);
				}
				else
				{
					xw.WriteStartAttribute("FontFamily");
					xw.WriteValue(tr.FontName);
					xw.WriteEndAttribute();
				}
			}

			xw.WriteStartAttribute("Foreground");
			xw.WriteColor(tr.Color);
			xw.WriteEndAttribute();

			if (tr.isItalic)
			{
				xw.WriteStartAttribute("FontStyle");
				xw.WriteValue("Italic");
				xw.WriteEndAttribute();
			}

			if (tr.isBold)
			{
				xw.WriteStartAttribute("FontWeight");
				xw.WriteValue("Bold");
				xw.WriteEndAttribute();
			}
		}

		protected void WriteOpenMask(IDefinition def, Instance instance)
		{
			//<Canvas x:Name="mask0">   
			 // <Canvas.Clip >     
			 //       <PathGeometry x:Name="inst_rt_0" Figures="M -10.000,111.000 L 62.000,46.000... " />
			 // </Canvas.Clip>  
			//</Canvas>

			xw.WriteStartElement("Canvas"); // this will be closed when the mask depth level is equaled

			//string name = GetInstanceName(instance) + VexObject.MaskPrefix + instance.Depth;
			string name = instancePrefix + instName;
			xw.WriteStartAttribute("x:Name");
			xw.WriteValue(name);
			xw.WriteEndAttribute();

			xw.WriteStartElement("Canvas.Clip");
			xw.WriteStartElement("PathGeometry");

			if (def is Symbol)
			{
				Point offset = new Point(0, 0);
				if (instance.Transformations.Count > 0)
				{
					offset.X = instance.Transformations[0].Matrix.TranslateX;
					offset.Y = instance.Transformations[0].Matrix.TranslateY;
				}
				WriteClipPoints(((Symbol)def).Shapes, offset);
			}

			xw.WriteEndElement(); // PathGeometry
			xw.WriteEndElement(); // Canvas.Clip

			//one more element to close at end of clipping
		}
		protected void WriteClipPoints(List<Shape> shapes, Point offset)
		{
			xw.WriteStartAttribute("Figures");
			for (int shp = 0; shp < shapes.Count; shp++)
			{
				if (shapes[shp].Fill != null)
				{
					List<IShapeData> sh = shapes[shp].ShapeData;
					xw.WriteMoveTo(sh[0].StartPoint + offset);
					Point lastPoint = sh[0].StartPoint + offset;

					for (int i = 0; i < sh.Count; i++)
					{
						IShapeData sd = sh[i];
						if (lastPoint != sd.StartPoint + offset)
						{
							xw.WriteMoveTo(sd.StartPoint + offset);
						}
						switch (sd.SegmentType)
						{
							case SegmentType.Line:
								xw.WriteLineTo(sd.EndPoint + offset);
								lastPoint = sd.EndPoint + offset;
								break;

							case SegmentType.CubicBezier:
								CubicBezier cb = (CubicBezier)sd;
								xw.WriteCubicCurveTo(cb.Control0 + offset, cb.Control1 + offset, cb.Anchor1 + offset);
								lastPoint = cb.EndPoint + offset;
								break;

							case SegmentType.QuadraticBezier:
								QuadBezier qb = (QuadBezier)sd;
								xw.WriteQuadraticCurveTo(qb.Control + offset, qb.Anchor1 + offset);
								lastPoint = qb.EndPoint + offset;
								break;
						}
					}
					if (shp < shapes.Count - 1)
					{
						xw.WriteValue(" Z ");
					}
				}
			}
			xw.WriteEndAttribute();
		}
		protected void RenderPath(FillStyle fs, StrokeStyle ss, List<IShapeData> sh, bool silverlight)
		{
			// <Path Fill="#FFFF0000" 
			// StrokeThickness="0.00491913" StrokeLineJoin="Round" Stroke="#FF014393"
			// Data="M 196.667,4L 388.667,100L 388.667,292L 196.667,388L 4.66669,292L 4.66669,100L 196.667,4 Z "/>
			if (sh.Count == 0)
			{
				return;
			}
			
			xw.WriteStartElement("Path");

			bool isGradient = false;
			bool isTiledBitmap = false;

			if (fs != null)
			{
				if (fs.FillType == FillType.Solid)
				{
					Color c = ((SolidFill)fs).Color;
					xw.WriteStartAttribute("Fill");
					xw.WriteColor(c);
					xw.WriteEndAttribute();

					// try to clean up faint edges
					if (ss == null && c != new Color(0xFF,0xFF,0xFF) && c.A != 0)
					{
						ss = new SolidStroke(0.3F, c);
					}
				}
				else if(
					fs.FillType == FillType.Linear || 
					fs.FillType == FillType.Radial || 
					fs.FillType == FillType.Focal)
				{
					isGradient = true;
				}
				else if (fs.FillType == FillType.Image)
				{
					// Fill="{StaticResource vb_1}" 
					ImageFill img = (ImageFill)fs;
					if (img.IsTiled || silverlight) 
					{
						isTiledBitmap = true;// this causes bitmap to be written inline
					}
					else
					{
						string brushName = imageBrushes[img.ImagePath];
						xw.WriteStartAttribute("Fill");
						xw.WriteValue("{StaticResource " + brushName + "}");
						xw.WriteEndAttribute();
					}
				}
			}
			if (ss != null)
			{
				if (ss is SolidStroke)
				{
					// StrokeThickness="3" StrokeLineJoin="Round" Stroke="#FF014393"
					// StrokeStartLineCap="Round"
					// StrokeEndLineCap="Round" 
					SolidStroke st = (SolidStroke)ss;

					xw.WriteStartAttribute("StrokeThickness");
					xw.WriteFloat(st.LineWidth);
					xw.WriteEndAttribute();

					xw.WriteStartAttribute("StrokeLineJoin");
					xw.WriteString("Round");
					xw.WriteEndAttribute();

					xw.WriteStartAttribute("StrokeStartLineCap");
					xw.WriteString("Round");
					xw.WriteEndAttribute();

					xw.WriteStartAttribute("StrokeEndLineCap");
					xw.WriteString("Round");
					xw.WriteEndAttribute();

					xw.WriteStartAttribute("Stroke");
					xw.WriteColor(st.Color);
					xw.WriteEndAttribute();
				}
			}
			float minX = float.PositiveInfinity;
			float minY = float.PositiveInfinity;
			float maxX = float.NegativeInfinity;
			float maxY = float.NegativeInfinity;

			xw.WriteStartAttribute("Data");

			xw.WriteMoveTo(sh[0].StartPoint);

			Point lastPoint = sh[0].StartPoint;

			for (int i = 0; i < sh.Count; i++)
			{
				IShapeData sd = sh[i];
				if (lastPoint != sd.StartPoint)
				{
					xw.WriteMoveTo(sd.StartPoint);
				}
				switch (sd.SegmentType)
				{
					case SegmentType.Line:
						xw.WriteLineTo(sd.EndPoint);
						lastPoint = sd.EndPoint;
						break;

					case SegmentType.CubicBezier:
						CubicBezier cb = (CubicBezier)sd;
						xw.WriteCubicCurveTo(cb.Control0, cb.Control1, cb.Anchor1);
						lastPoint = cb.EndPoint;
						minX = Math.Min(minX, cb.Control0.X);
						maxX = Math.Max(maxX, cb.Control0.X);
						minY = Math.Min(minY, cb.Control0.Y);
						maxY = Math.Max(maxY, cb.Control0.Y);
						minX = Math.Min(minX, cb.Control1.X);
						maxX = Math.Max(maxX, cb.Control1.X);
						minY = Math.Min(minY, cb.Control1.Y);
						maxY = Math.Max(maxY, cb.Control1.Y);
						break;

					case SegmentType.QuadraticBezier:
						QuadBezier qb = (QuadBezier)sd;
						xw.WriteQuadraticCurveTo(qb.Control, qb.Anchor1);
						lastPoint = qb.EndPoint;
						minX = Math.Min(minX, qb.Control.X);
						maxX = Math.Max(maxX, qb.Control.X);
						minY = Math.Min(minY, qb.Control.Y);
						maxY = Math.Max(maxY, qb.Control.Y);
						break;
				}

				// need bounds for gradient :(
				if (isGradient)
				{
					minX = Math.Min(minX, sd.StartPoint.X);
					maxX = Math.Max(maxX, sd.StartPoint.X);
					minY = Math.Min(minY, sd.StartPoint.Y);
					maxY = Math.Max(maxY, sd.StartPoint.Y);

					minX = Math.Min(minX, sd.EndPoint.X);
					maxX = Math.Max(maxX, sd.EndPoint.X);
					minY = Math.Min(minY, sd.EndPoint.Y);
					maxY = Math.Max(maxY, sd.EndPoint.Y);
				}
			}
			xw.WriteEndAttribute();

			if (isGradient)
			{
				GradientFill gf = (GradientFill)fs;
				// need a gradient def here
				if (fs.FillType == FillType.Linear)
				{
					//<Path.Fill>
					//    <LinearGradientBrush StartPoint="0.14706,0.532137" EndPoint="1.14962,0.55353">
					//        <LinearGradientBrush.GradientStops>
					//            <GradientStop Color="#FF4A4A4A" Offset="0"/>
					//            <GradientStop Color="#FFB0B0B0" Offset="0.412067"/>
					//            <GradientStop Color="#FFBBBBBB" Offset="0.638141"/>
					//            <GradientStop Color="#FF545454" Offset="1"/>
					//        </LinearGradientBrush.GradientStops>
					//    </LinearGradientBrush>
					//</Path.Fill>
					xw.WriteStartElement("Path.Fill");

					xw.WriteStartElement("LinearGradientBrush");

					Matrix m = gf.Transform;
					Rectangle r = gf.Rectangle;
					ms2.Matrix m2 = new ms2.Matrix(m.ScaleX, m.Rotate0, m.Rotate1, m.ScaleY, m.TranslateX, m.TranslateY);
					float midY = r.Point.Y + (r.Size.Height / 2);
					ms.PointF pt0 = new ms.PointF(r.Point.X, midY);
					ms.PointF pt1 = new ms.PointF(r.Point.X + r.Size.Width, midY);
					ms.PointF[] pts = new ms.PointF[]{pt0, pt1};
					m2.TransformPoints(pts);

					float ratX = 1 / (maxX - minX);
					float ratY = 1 / (maxY - minY);
					float d0x = (pts[0].X - minX) * ratX;
					float d0y = (pts[0].Y - minY) * ratY;
					float d1x = (pts[1].X - minX) * ratX;
					float d1y = (pts[1].Y - minY) * ratY;

					xw.WriteStartAttribute("StartPoint");
					xw.WritePoint(new Point(d0x, d0y));
					xw.WriteEndAttribute();

					xw.WriteStartAttribute("EndPoint");
					xw.WritePoint(new Point(d1x, d1y));
					xw.WriteEndAttribute();
					
					xw.WriteStartAttribute("SpreadMethod");
					xw.WriteValue("Pad");
					xw.WriteEndAttribute();

					xw.WriteStartElement("LinearGradientBrush.GradientStops");
					for (int i = 0; i < gf.Stops.Count; i++)
					{
						xw.WriteStartElement("GradientStop");

						xw.WriteStartAttribute("Color");
						xw.WriteColor(gf.Fills[i]);
						xw.WriteEndAttribute();

						xw.WriteStartAttribute("Offset");
						xw.WriteFloat(gf.Stops[i]);
						xw.WriteEndAttribute();

						xw.WriteEndElement(); // GradientStop
					}
					xw.WriteEndElement(); // LinearGradientBrush.GradientStops
					xw.WriteEndElement(); // LinearGradientBrush
					xw.WriteEndElement(); // Path.Fill
				}
				else if (fs.FillType == FillType.Radial)
				{
					//<Ellipse.Fill>
					//    <RadialGradientBrush RadiusX="0.622359" RadiusY="0.604589" Center="0.5,0.5" GradientOrigin="0.5,0.5">
					//        <RadialGradientBrush.RelativeTransform>
					//            <TransformGroup/>
					//        </RadialGradientBrush.RelativeTransform>
					//        <GradientStop Color="#95000000" Offset="0.347222"/>
					//        <GradientStop Color="#007877A7" Offset="0.773148"/>
					//    </RadialGradientBrush>
					//</Ellipse.Fill>

					xw.WriteStartElement("Path.Fill");

					xw.WriteStartElement("RadialGradientBrush");

					Matrix m = gf.Transform;
					Rectangle r = gf.Rectangle;
					ms2.Matrix m2 = new ms2.Matrix(m.ScaleX, m.Rotate0, m.Rotate1, m.ScaleY, m.TranslateX, m.TranslateY);
					float midX = r.Point.X + (r.Size.Width / 2);
					float midY = r.Point.Y + (r.Size.Height / 2);
					ms.PointF pt0 = new ms.PointF(midX, midY); // center
					ms.PointF pt1 = new ms.PointF(r.Point.X + r.Size.Width, midY); // radius vector
					ms.PointF[] pts = new ms.PointF[] { pt0, pt1 };
					m2.TransformPoints(pts);

					float ratX = 1 / (maxX - minX);
					float ratY = 1 / (maxY - minY);
					float d0x = (pts[0].X - minX) * ratX;
					float d0y = (pts[0].Y - minY) * ratY;
					float d1x = (pts[1].X - pts[0].X);
					//float d1y = (pts[1].Y - pts[0].Y) * ratY;

					float rad = (float)Math.Sqrt(d1x*d1x);
					xw.WriteStartAttribute("RadiusX");
					xw.WriteFloat(rad * ratX);
					xw.WriteEndAttribute();
					xw.WriteStartAttribute("RadiusY");
					xw.WriteFloat(rad * ratY);
					xw.WriteEndAttribute();

					xw.WriteStartAttribute("Center");
					xw.WritePoint(new Point(d0x, d0y));
					xw.WriteEndAttribute();

					xw.WriteStartAttribute("GradientOrigin");
					xw.WritePoint(new Point(d0x, d0y));
					xw.WriteEndAttribute();

					xw.WriteStartAttribute("SpreadMethod");
					xw.WriteValue("Pad");
					xw.WriteEndAttribute();

					//xw.WriteStartElement("RadialGradientBrush.GradientStops");
					for (int i = 0; i < gf.Stops.Count; i++)
					{
						xw.WriteStartElement("GradientStop");

						xw.WriteStartAttribute("Color");
						xw.WriteColor(gf.Fills[i]);
						xw.WriteEndAttribute();

						xw.WriteStartAttribute("Offset");
						xw.WriteFloat(1 - gf.Stops[i]); // xaml fill is reversed from gdi
						xw.WriteEndAttribute();

						xw.WriteEndElement(); // GradientStop
					}
					//xw.WriteEndElement(); // LinearGradientBrush.GradientStops
					xw.WriteEndElement(); // LinearGradientBrush
					xw.WriteEndElement(); // Path.Fill
				}
			}
			else if(isTiledBitmap)
			{				   
				//<Path.Fill>
				//   <ImageBrush ImageSource="Resources\bmp_1.jpg" TileMode="Tile" RelativeTransform=".2,0,0,.2,0,0"/>
				//</Path.Fill>  

				ImageFill img = (ImageFill)fs;

				xw.WriteStartElement("Path.Fill");
				xw.WriteStartElement("ImageBrush");

				xw.WriteStartAttribute("ImageSource");
				xw.WriteValue(img.ImagePath);
				xw.WriteEndAttribute();

				if (!silverlight)
				{
					xw.WriteStartAttribute("TileMode");
					xw.WriteValue("Tile");
					xw.WriteEndAttribute();
				}

				//xw.WriteStartAttribute("ViewportUnits");
				//xw.WriteValue("Absolute");
				//xw.WriteEndAttribute();

				Matrix pMatrix = ApplyMatrixToShape(sh, img.Matrix, images[img.ImagePath].StrokeBounds);
				//Matrix pMatrix = ApplyMatrixToImage(img.Matrix, images[img.ImagePath].Bounds);
				xw.WriteStartAttribute("RelativeTransform");
				xw.WriteMatrix(pMatrix);
				//xw.WriteMatrix(img.Matrix);
				xw.WriteEndAttribute();

				xw.WriteEndElement(); // Path.Fill
				xw.WriteEndElement(); // ImageBrush
			}
			xw.WriteEndElement(); // Path

		}
		protected Matrix ApplyMatrixToImage(Matrix m, Rectangle imgBounds)
		{
			return new Matrix(
				m.ScaleX * imgBounds.Size.Width,
				m.Rotate0, 
				m.Rotate1, 
				m.ScaleY * imgBounds.Size.Height, 
				m.TranslateX, 
				m.TranslateY);
		
		}
		protected Matrix ApplyMatrixToShape(List<IShapeData> sh, Matrix m, Rectangle imgBounds)
		{
			float maxX = int.MinValue;
			float maxY = int.MinValue;
			float minX = int.MaxValue;
			float minY = int.MaxValue;
			// todo: aproximate bezier endings
			for (int i = 0; i < sh.Count; i++)
			{
				IShapeData s = sh[i];
				if (s.StartPoint.X < minX) minX = s.StartPoint.X;
				if (s.StartPoint.Y < minY) minY = s.StartPoint.Y;
				if (s.EndPoint.X < minX) minX = s.EndPoint.X;
				if (s.EndPoint.Y < minY) minY = s.EndPoint.Y;

				if (s.StartPoint.X > maxX) maxX = s.StartPoint.X;
				if (s.StartPoint.Y > maxY) maxY = s.StartPoint.Y;
				if (s.EndPoint.X > maxX) maxX = s.EndPoint.X;
				if (s.EndPoint.Y > maxY) maxY = s.EndPoint.Y;
			}

			// todo: this doesn't work well with rotation, or at all with skew
			float w = maxX - minX;
			float h = maxY - minY;

			float ws = (imgBounds.Size.Width / w);
			float hs = (imgBounds.Size.Height / h);
			float xScale = m.ScaleX * ws;
			float yScale = m.ScaleY * hs;

			float r0 = m.Rotate0 * ws;
			float r1 = m.Rotate1 * hs;

			float tx = (m.TranslateX - minX) / w;
			float ty = (m.TranslateY - minY) / h;

			return new Matrix(xScale, r0, r1, yScale, tx, ty);

			//float ws = (imgBounds.Size.Width / w);
			//float hs = (imgBounds.Size.Height / h);

			//float tx = (m.TranslateX - minX) / w;
			//float ty = (m.TranslateY - minY) / h;

			//System.Drawing.Drawing2D.Matrix mx =
			//    new System.Drawing.Drawing2D.Matrix(m.ScaleX, m.Rotate0, m.Rotate1, m.ScaleY, 0, 0);
			//System.Drawing.PointF[] pts = new System.Drawing.PointF[]{
			//    new System.Drawing.PointF(1, imgBounds.Size.Height/imgBounds.Size.Width)
			//};
			//mx.TransformPoints(pts);
			//float imgRot = (float)(Math.Atan2(-imgBounds.Size.Height, imgBounds.Size.Width)/Math.PI * 180 + 45);
			//float rot = (float)(Math.Atan2(-pts[0].Y, pts[0].X)/Math.PI * 180 + 45) - imgRot;

			//mx = new System.Drawing.Drawing2D.Matrix();
			//mx.Scale(m.ScaleX * ws, m.ScaleY * hs, System.Drawing.Drawing2D.MatrixOrder.Append);
			//mx.Rotate(rot, System.Drawing.Drawing2D.MatrixOrder.Append);
			//float[] els = mx.Elements;
			//return new Matrix(els[0], els[1], els[2], els[3], tx, ty);
		}

		protected void WriteWatermarkDefinitions()
		{
			xw.WriteRaw(Environment.NewLine + @"    <Canvas x:Key=""d_1"" Width=""101"" Height=""24"" RenderTransformOrigin=""0,0"" Canvas.Left=""0"" Canvas.Top=""0"">" + Environment.NewLine);
			xw.WriteRaw(@"      <Path Data=""M 0.000,0.000 L 100.000,0.000 L 100.000,23.000 L 0.000,23.000 L 0.000,0.000 "">" + Environment.NewLine);
			xw.WriteRaw(@"        <Path.Fill>" + Environment.NewLine);
			xw.WriteRaw(@"          <LinearGradientBrush StartPoint=""0.500,0.012 "" EndPoint=""0.500,0.997 "" SpreadMethod=""Pad"">" + Environment.NewLine);
			xw.WriteRaw(@"            <LinearGradientBrush.GradientStops>" + Environment.NewLine);
			xw.WriteRaw(@"              <GradientStop Color=""#FF959595"" Offset=""0.000"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <GradientStop Color=""#FFFFFFFF"" Offset=""1.000"" />" + Environment.NewLine);
			xw.WriteRaw(@"            </LinearGradientBrush.GradientStops>" + Environment.NewLine);
			xw.WriteRaw(@"          </LinearGradientBrush>" + Environment.NewLine);
			xw.WriteRaw(@"        </Path.Fill>" + Environment.NewLine);
			xw.WriteRaw(@"      </Path>" + Environment.NewLine);
			xw.WriteRaw(@"      <Path StrokeThickness=""1.000"" Stroke=""#FF333333"" Data=""M 0.000,0.000 L 100.000,0.000 L 100.000,23.000 L 0.000,23.000 L 0.000,0.000 "" />" + Environment.NewLine);
			xw.WriteRaw(@"    </Canvas>" + Environment.NewLine);
			xw.WriteRaw(@"    <VisualBrush x:Key=""v_1"" Visual=""{Binding Source={StaticResource d_1}}"" />" + Environment.NewLine);
			xw.WriteRaw(@"    <Canvas x:Key=""d_2"" Width=""32"" Height=""11"" RenderTransformOrigin=""0,0"" Canvas.Left=""0"" Canvas.Top=""0"">" + Environment.NewLine);
			xw.WriteRaw(@"      <Path Fill=""#FF000066"" Data=""M 0.000,8.950 Q 0.000,8.250 0.250,8.000 Q 0.500,7.650 0.950,7.650 L 1.500,7.850 L 1.850,8.450 L 2.100,9.000 L 3.050,9.550 L 4.550,9.850 Q 5.800,9.850 6.600,9.250 L 7.150,8.400 L 6.900,7.750 Q 6.650,7.400 6.100,7.200 L 4.450,6.850 Q 2.850,6.550 2.100,6.150 L 0.850,5.000 Q 0.350,4.250 0.400,3.400 Q 0.350,2.050 1.500,1.050 Q 2.600,0.000 4.450,0.000 L 5.800,0.200 L 6.950,0.650 Q 7.300,0.300 7.700,0.300 Q 8.100,0.300 8.350,0.600 L 8.600,1.550 L 8.600,3.000 L 8.350,3.950 L 7.700,4.250 L 7.050,4.050 L 6.750,3.400 L 6.500,2.750 L 5.700,2.150 L 4.450,1.900 Q 3.450,1.900 2.850,2.400 Q 2.250,2.850 2.250,3.400 L 2.500,4.050 L 3.200,4.550 L 5.000,4.950 L 7.200,5.600 Q 8.000,5.950 8.500,6.650 Q 9.000,7.400 9.000,8.400 Q 9.000,9.800 8.050,10.650 Q 6.700,11.750 4.700,11.750 L 3.200,11.550 L 1.750,11.000 L 1.350,11.400 L 0.950,11.450 Q 0.500,11.450 0.250,11.150 Q 0.000,10.850 0.000,10.200 L 0.000,8.950 M 9.950,1.300 Q 9.900,0.800 10.250,0.550 Q 10.500,0.250 11.200,0.300 L 13.700,0.300 L 14.700,0.550 L 14.950,1.250 L 14.700,1.900 Q 14.400,2.150 13.700,2.200 L 12.750,2.200 L 13.350,7.500 L 14.850,3.050 L 16.800,3.050 L 18.300,7.500 L 18.900,2.200 L 17.950,2.200 Q 17.200,2.150 16.950,1.900 Q 16.650,1.650 16.650,1.250 Q 16.650,0.800 16.950,0.550 Q 17.200,0.250 17.950,0.300 L 20.450,0.300 L 21.400,0.550 L 21.700,1.250 L 21.450,1.850 L 20.800,2.200 L 19.700,11.500 L 17.600,11.500 L 15.800,6.100 L 14.050,11.500 L 11.950,11.500 L 10.800,2.200 Q 10.350,2.100 10.150,1.900 Q 9.900,1.600 9.950,1.300 M 22.400,1.250 Q 22.400,0.800 22.700,0.550 Q 22.950,0.250 23.650,0.300 L 32.550,0.300 L 32.550,3.200 L 32.300,4.150 L 31.600,4.450 Q 31.200,4.450 30.950,4.150 Q 30.650,3.850 30.650,3.200 L 30.650,2.200 L 25.850,2.200 L 25.850,4.950 L 27.500,4.950 Q 27.500,4.200 27.650,3.950 Q 27.900,3.500 28.450,3.500 Q 28.850,3.500 29.150,3.850 L 29.400,4.800 L 29.400,6.950 L 29.150,7.950 L 28.450,8.250 Q 27.900,8.250 27.650,7.800 Q 27.500,7.550 27.500,6.850 L 25.850,6.850 L 25.850,9.600 L 27.800,9.600 L 28.750,9.850 L 29.050,10.550 L 28.750,11.200 L 27.800,11.500 L 23.650,11.500 L 22.700,11.200 Q 22.400,10.950 22.400,10.550 Q 22.400,10.100 22.700,9.850 L 23.650,9.600 L 23.950,9.600 L 23.950,2.200 L 23.650,2.200 L 22.700,1.900 Q 22.400,1.650 22.400,1.250 "" />" + Environment.NewLine);
			xw.WriteRaw(@"    </Canvas>" + Environment.NewLine);
			xw.WriteRaw(@"    <VisualBrush x:Key=""v_2"" Visual=""{Binding Source={StaticResource d_2}}"" />" + Environment.NewLine);
			xw.WriteRaw(@"    <Canvas x:Key=""d_3"" Width=""7"" Height=""10"" RenderTransformOrigin=""0,0"" Canvas.Left=""0"" Canvas.Top=""0"">" + Environment.NewLine);
			xw.WriteRaw(@"      <Path Fill=""#FF006699"" Data=""M 0.000,0.000 L 0.000,10.300 L 7.150,5.150 L 0.000,0.000 "" />" + Environment.NewLine);
			xw.WriteRaw(@"    </Canvas>" + Environment.NewLine);
			xw.WriteRaw(@"    <VisualBrush x:Key=""v_3"" Visual=""{Binding Source={StaticResource d_3}}"" />" + Environment.NewLine);
			xw.WriteRaw(@"    <Canvas x:Key=""d_4"" Width=""44"" Height=""11"" RenderTransformOrigin=""0,0"" Canvas.Left=""0"" Canvas.Top=""0"">" + Environment.NewLine);
			xw.WriteRaw(@"      <Path Fill=""#FF000066"" Data=""M 0.050,10.300 Q 0.000,9.850 0.300,9.600 Q 0.600,9.350 1.150,9.350 L 4.250,5.500 L 1.300,1.950 L 0.450,1.650 L 0.200,1.000 Q 0.200,0.550 0.500,0.300 Q 0.750,0.000 1.450,0.050 L 3.200,0.050 L 4.150,0.300 L 4.450,1.000 L 4.250,1.550 L 3.750,1.950 L 5.500,4.050 L 7.200,1.950 L 6.700,1.550 L 6.500,1.000 Q 6.500,0.550 6.800,0.300 Q 7.050,0.000 7.750,0.050 L 9.500,0.050 L 10.500,0.300 L 10.750,1.000 L 10.500,1.650 Q 10.200,1.900 9.650,1.950 L 6.700,5.550 L 9.850,9.350 Q 10.400,9.350 10.700,9.600 L 10.850,9.750 L 11.050,9.600 Q 11.350,9.300 12.050,9.350 L 15.000,1.950 L 13.750,1.950 Q 13.050,1.900 12.800,1.650 Q 12.500,1.400 12.500,1.000 Q 12.500,0.550 12.800,0.300 Q 13.050,0.000 13.750,0.050 L 17.850,0.050 L 21.600,9.350 L 22.500,9.500 L 23.250,9.350 L 23.250,1.950 Q 22.800,1.850 22.550,1.600 Q 22.250,1.350 22.250,1.000 Q 22.250,0.550 22.600,0.300 Q 22.850,0.000 23.550,0.050 L 25.600,0.050 L 28.150,5.750 L 30.700,0.050 L 32.800,0.050 L 33.750,0.300 L 34.050,1.000 L 33.800,1.600 L 33.050,1.950 L 33.050,9.350 L 33.950,9.600 L 34.200,10.300 L 33.950,10.950 L 32.950,11.250 L 30.500,11.250 L 29.500,10.950 Q 29.200,10.700 29.200,10.300 Q 29.200,9.850 29.500,9.600 L 30.500,9.350 L 31.150,9.350 L 31.150,3.700 L 29.000,8.600 L 27.350,8.600 L 25.150,3.700 L 25.150,9.350 L 25.850,9.350 Q 26.500,9.350 26.800,9.600 L 27.100,10.300 L 26.800,10.950 Q 26.500,11.200 25.850,11.250 L 23.350,11.250 L 22.500,11.050 L 21.650,11.250 L 19.100,11.250 Q 18.400,11.200 18.150,10.950 Q 17.800,10.700 17.850,10.300 Q 17.800,9.850 18.150,9.600 Q 18.400,9.350 19.100,9.350 L 19.600,9.350 L 19.150,8.200 L 14.550,8.200 L 14.100,9.350 L 14.550,9.350 L 15.500,9.600 L 15.800,10.300 L 15.500,10.950 L 14.550,11.250 L 12.000,11.250 Q 11.300,11.200 11.050,10.950 L 10.900,10.800 L 10.700,10.950 L 9.700,11.250 L 7.600,11.250 L 6.650,10.950 Q 6.300,10.700 6.350,10.300 Q 6.350,9.850 6.650,9.650 Q 6.900,9.350 7.400,9.350 L 5.550,7.000 L 3.600,9.350 Q 4.100,9.350 4.400,9.650 L 4.650,10.300 L 4.400,10.950 Q 4.050,11.200 3.400,11.250 L 1.300,11.250 Q 0.600,11.200 0.300,10.950 Q 0.000,10.700 0.050,10.300 M 15.300,6.300 L 18.350,6.300 L 16.800,2.550 L 15.300,6.300 M 34.400,1.000 Q 34.400,0.550 34.700,0.300 Q 35.000,0.000 35.650,0.050 L 39.750,0.050 L 40.750,0.300 L 41.050,1.000 L 40.750,1.650 L 39.750,1.950 L 38.650,1.950 L 38.650,9.350 L 42.750,9.350 L 42.750,7.550 Q 42.750,6.850 43.000,6.600 Q 43.250,6.300 43.700,6.300 Q 44.100,6.300 44.350,6.600 L 44.600,7.550 L 44.600,11.250 L 35.650,11.250 Q 35.000,11.200 34.700,10.950 Q 34.400,10.700 34.400,10.300 Q 34.400,9.850 34.700,9.600 Q 35.000,9.350 35.650,9.350 L 36.750,9.350 L 36.750,1.950 L 35.650,1.950 Q 35.000,1.900 34.700,1.650 Q 34.400,1.400 34.400,1.000 "" />" + Environment.NewLine);
			xw.WriteRaw(@"    </Canvas>" + Environment.NewLine);
			xw.WriteRaw(@"    <VisualBrush x:Key=""v_4"" Visual=""{Binding Source={StaticResource d_4}}"" />" + Environment.NewLine);
			xw.WriteRaw(@"    <Canvas x:Key=""d_5"" Width=""95"" Height=""17"" RenderTransformOrigin=""0,0"" Canvas.Left=""0"" Canvas.Top=""0"">" + Environment.NewLine);
			xw.WriteRaw(@"      <Path Fill=""#FF800000"" Data=""M 0.000,11.500 Q 0.000,10.000 0.700,8.700 Q 1.350,7.400 2.650,6.700 Q 3.850,5.950 5.300,5.950 L 6.850,6.150 L 7.850,6.550 L 8.100,6.400 L 8.750,6.250 Q 9.300,6.250 9.700,6.650 Q 10.100,7.000 10.100,7.900 L 10.100,9.400 Q 10.100,10.250 9.700,10.600 L 9.750,10.600 Q 9.350,11.050 8.750,11.050 Q 8.150,11.050 7.850,10.700 Q 7.500,10.450 7.400,9.700 L 7.250,9.400 L 7.250,9.350 L 6.450,8.900 L 5.350,8.700 Q 4.650,8.700 4.100,9.000 L 4.150,8.950 Q 3.550,9.250 3.150,9.950 Q 2.700,10.600 2.700,11.550 L 2.700,12.650 Q 2.650,13.700 3.450,14.450 Q 4.250,15.150 5.700,15.150 L 7.200,14.950 L 7.900,14.450 L 8.400,14.000 L 8.450,14.000 L 9.000,13.850 Q 9.550,13.800 9.950,14.250 L 9.950,14.300 Q 10.350,14.650 10.350,15.200 L 9.900,16.300 L 8.350,17.400 L 5.700,17.900 Q 4.000,17.850 2.700,17.200 Q 1.550,16.600 0.750,15.400 Q -0.050,14.150 0.000,12.700 L 0.000,11.500 M 10.750,13.350 Q 10.700,12.150 11.400,11.050 Q 12.000,9.900 13.250,9.250 Q 14.450,8.600 15.800,8.600 Q 17.100,8.600 18.350,9.250 Q 19.550,9.900 20.200,11.100 Q 20.800,12.200 20.800,13.400 Q 20.800,14.550 20.200,15.600 Q 19.550,16.650 18.300,17.300 L 18.350,17.300 Q 17.100,17.900 15.800,17.900 Q 14.450,17.900 13.250,17.300 Q 12.000,16.650 11.400,15.600 Q 10.750,14.550 10.750,13.350 M 12.350,2.700 Q 12.300,2.350 12.600,2.150 Q 12.750,1.900 13.300,1.950 L 13.400,1.950 L 13.400,1.300 Q 13.350,0.750 13.600,0.600 Q 13.800,0.350 14.150,0.350 Q 14.500,0.300 14.750,0.550 L 14.750,0.600 L 14.950,1.300 L 14.950,1.950 L 16.550,1.950 L 17.250,2.100 L 17.250,2.150 L 17.500,2.700 L 17.250,3.250 L 17.250,3.300 L 16.550,3.500 L 14.950,3.500 L 14.950,5.250 L 15.000,5.450 L 15.550,5.600 L 16.850,5.300 L 17.350,5.100 Q 17.650,5.100 17.900,5.350 L 17.950,5.350 L 18.100,5.700 L 18.300,5.550 L 18.300,5.500 L 18.700,5.400 L 18.700,1.550 Q 18.250,1.550 18.100,1.350 L 18.050,1.350 L 17.800,0.800 Q 17.800,0.450 18.050,0.250 L 18.100,0.200 L 18.800,0.000 L 19.950,0.000 L 20.150,0.050 L 20.250,0.250 L 20.250,2.000 L 20.550,1.900 L 21.250,1.800 L 22.300,2.000 L 23.100,2.650 L 23.400,3.800 L 23.400,5.400 L 23.800,5.500 L 23.800,5.550 Q 24.150,5.750 24.150,6.200 L 23.950,6.750 L 23.900,6.750 L 23.200,7.000 L 22.050,7.000 Q 21.550,6.950 21.350,6.750 L 21.100,6.200 Q 21.100,5.750 21.500,5.550 L 21.500,5.500 L 21.850,5.400 L 21.850,3.850 L 21.800,3.500 L 21.750,3.500 L 21.250,3.350 L 20.800,3.450 L 20.250,3.900 L 20.250,5.400 L 20.600,5.500 L 20.600,5.550 Q 21.000,5.750 21.000,6.200 L 20.750,6.750 L 20.750,6.800 L 20.050,7.000 L 18.850,7.000 L 18.150,6.750 L 17.950,6.400 L 17.900,6.450 L 16.850,6.950 L 15.550,7.150 Q 14.450,7.150 13.950,6.650 Q 13.350,6.150 13.400,5.450 L 13.400,3.500 L 13.300,3.500 Q 12.750,3.500 12.600,3.300 Q 12.300,3.050 12.350,2.700 M 13.450,13.400 Q 13.450,14.050 14.100,14.600 Q 14.750,15.150 15.800,15.200 Q 16.750,15.150 17.450,14.600 Q 18.050,14.050 18.100,13.400 Q 18.050,12.700 17.600,12.150 Q 16.900,11.300 15.800,11.350 Q 14.750,11.300 14.100,11.950 Q 13.450,12.600 13.450,13.400 M 21.000,16.250 Q 21.000,15.550 21.650,15.100 L 22.300,14.900 L 22.300,11.550 L 21.650,11.250 L 21.600,11.200 Q 21.200,10.800 21.200,10.200 Q 21.200,9.600 21.650,9.250 L 21.650,9.200 Q 22.000,8.850 22.900,8.850 L 24.550,8.850 L 24.900,9.000 L 24.950,9.100 L 25.450,8.850 L 26.900,8.600 Q 28.650,8.600 29.700,9.750 Q 30.550,10.650 30.550,12.100 L 30.550,14.950 Q 31.000,15.000 31.250,15.250 L 31.250,15.300 Q 31.600,15.650 31.650,16.250 L 31.250,17.250 L 31.200,17.300 L 30.000,17.650 L 28.400,17.650 Q 27.500,17.600 27.200,17.250 Q 26.750,16.850 26.750,16.250 Q 26.750,15.650 27.150,15.300 L 27.150,15.250 Q 27.400,15.000 27.850,14.950 L 27.850,12.050 L 27.700,11.600 L 27.700,11.550 L 26.800,11.350 L 25.950,11.500 L 25.050,12.300 L 25.050,14.900 L 25.700,15.100 Q 26.350,15.500 26.350,16.250 Q 26.300,16.850 25.900,17.250 Q 25.550,17.600 24.650,17.650 L 22.650,17.650 Q 21.750,17.600 21.450,17.250 Q 21.000,16.850 21.000,16.250 M 24.100,4.500 Q 24.100,3.300 25.000,2.550 Q 25.850,1.800 27.000,1.800 L 28.250,2.050 Q 28.800,2.250 29.100,2.550 L 29.750,3.550 L 29.900,4.550 L 29.900,4.950 L 29.850,5.150 L 29.650,5.250 L 29.350,5.250 L 29.700,5.450 L 29.900,6.000 L 29.700,6.550 Q 29.450,6.800 28.600,6.950 L 27.050,7.150 Q 25.700,7.150 24.900,6.400 Q 24.100,5.600 24.100,4.500 M 26.050,5.250 L 26.200,5.400 L 27.150,5.600 L 28.550,5.350 L 29.000,5.250 L 26.050,5.250 M 26.100,3.650 L 27.950,3.650 L 27.750,3.550 L 27.000,3.350 L 26.250,3.550 L 26.100,3.650 M 31.150,10.200 Q 31.150,9.600 31.600,9.250 L 31.600,9.200 Q 31.900,8.850 32.800,8.850 L 35.150,8.850 Q 36.000,8.850 36.400,9.200 L 36.400,9.250 Q 36.800,9.600 36.800,10.200 Q 36.800,10.950 36.200,11.400 L 36.150,11.400 L 35.750,11.550 L 36.950,13.900 L 38.100,11.550 L 37.700,11.400 L 37.650,11.400 Q 37.000,10.950 37.000,10.200 Q 37.000,9.600 37.450,9.250 L 37.450,9.200 Q 37.750,8.850 38.650,8.850 L 41.100,8.850 Q 41.950,8.850 42.300,9.200 L 42.350,9.250 L 42.750,10.200 L 42.350,11.200 L 42.300,11.250 L 41.100,11.550 L 38.250,17.350 L 38.100,17.550 L 37.850,17.650 L 36.000,17.650 L 35.750,17.550 L 35.600,17.350 L 32.750,11.550 Q 31.900,11.550 31.600,11.200 Q 31.150,10.800 31.150,10.200 M 42.400,13.300 Q 42.400,11.250 43.900,10.000 Q 45.350,8.750 47.300,8.750 L 49.450,9.150 L 50.850,10.000 L 52.000,11.750 L 52.050,11.750 L 52.300,13.400 L 52.300,14.150 L 52.200,14.350 L 52.050,14.400 L 45.000,14.400 L 45.750,15.100 Q 46.450,15.500 47.550,15.500 L 50.200,15.100 L 51.200,14.900 Q 51.650,14.850 51.950,15.250 L 52.000,15.250 L 52.350,16.050 L 51.950,16.800 L 51.950,16.850 L 50.100,17.500 L 47.450,17.800 Q 45.150,17.750 43.800,16.500 Q 42.400,15.200 42.400,13.300 M 45.100,12.100 L 49.600,12.100 L 48.850,11.400 Q 48.200,11.050 47.350,11.050 Q 46.500,11.050 45.900,11.400 L 45.100,12.100 M 53.200,16.250 Q 53.200,15.650 53.650,15.300 L 53.650,15.250 Q 54.000,14.900 54.900,14.900 L 55.450,14.900 L 55.450,11.550 L 55.300,11.550 Q 54.400,11.550 54.050,11.200 Q 53.600,10.800 53.600,10.200 Q 53.600,9.600 54.050,9.250 L 54.050,9.200 Q 54.400,8.850 55.300,8.850 L 57.700,8.850 L 58.050,9.000 L 58.150,9.350 L 58.150,9.500 L 59.250,8.900 L 60.650,8.600 Q 61.650,8.600 62.600,9.350 Q 63.350,9.950 63.350,10.600 L 62.950,11.600 Q 62.550,12.000 61.950,12.000 Q 61.500,12.000 60.950,11.550 L 60.600,11.350 Q 60.350,11.350 59.800,11.750 Q 59.100,12.150 58.150,12.950 L 58.150,14.900 L 60.200,14.900 Q 61.050,14.900 61.400,15.250 L 61.400,15.300 Q 61.850,15.650 61.850,16.250 Q 61.850,16.850 61.400,17.250 Q 61.050,17.600 60.200,17.650 L 54.900,17.650 L 53.650,17.250 Q 53.200,16.850 53.200,16.250 M 64.100,10.200 Q 64.100,9.600 64.550,9.250 L 64.550,9.200 Q 64.900,8.850 65.800,8.850 L 65.950,8.850 L 65.950,7.750 Q 65.950,6.850 66.300,6.500 Q 66.650,6.100 67.300,6.100 Q 67.900,6.100 68.300,6.500 Q 68.650,6.850 68.650,7.750 L 68.650,8.850 L 71.450,8.850 Q 72.300,8.850 72.650,9.200 L 72.700,9.250 Q 73.050,9.600 73.100,10.200 L 72.700,11.200 L 72.650,11.250 L 71.450,11.550 L 68.650,11.550 L 68.650,14.600 L 68.750,15.000 L 69.700,15.200 L 72.000,14.650 L 72.000,14.700 Q 72.550,14.350 72.900,14.400 Q 73.400,14.350 73.850,14.800 Q 74.200,15.200 74.200,15.750 Q 74.200,16.300 73.800,16.700 L 71.950,17.550 L 69.700,17.900 Q 67.850,17.900 66.950,17.100 Q 65.950,16.200 65.950,15.000 L 65.950,11.550 L 65.800,11.550 Q 64.900,11.550 64.550,11.200 Q 64.100,10.800 64.100,10.200 M 74.150,13.300 Q 74.150,11.250 75.650,10.000 Q 77.100,8.750 79.050,8.750 L 81.200,9.150 L 82.600,10.000 Q 83.300,10.700 83.800,11.750 L 84.050,13.400 L 84.050,14.150 L 83.950,14.350 L 83.800,14.400 L 76.750,14.400 L 77.500,15.100 L 79.300,15.500 L 81.950,15.100 L 83.000,14.900 Q 83.400,14.850 83.700,15.250 L 83.750,15.250 L 84.100,16.050 Q 84.100,16.500 83.750,16.800 L 83.700,16.850 L 81.900,17.500 L 79.200,17.800 Q 76.900,17.750 75.550,16.500 Q 74.150,15.200 74.150,13.300 M 76.850,12.100 L 81.350,12.100 L 80.600,11.400 L 80.650,11.400 Q 79.950,11.050 79.100,11.050 Q 78.250,11.050 77.650,11.400 L 76.850,12.100 M 84.550,13.450 Q 84.500,11.400 85.950,10.000 Q 87.350,8.600 89.400,8.600 L 90.900,8.850 L 91.550,9.150 L 91.550,8.200 L 90.550,7.850 L 90.500,7.850 Q 90.100,7.450 90.100,6.900 Q 90.100,6.250 90.500,5.900 Q 90.900,5.500 91.750,5.500 L 93.800,5.500 Q 94.000,5.500 94.150,5.650 L 94.300,5.950 L 94.300,14.900 L 95.350,15.250 L 95.350,15.300 Q 95.750,15.650 95.750,16.250 Q 95.750,16.850 95.350,17.250 L 95.350,17.300 L 94.100,17.650 L 92.050,17.650 L 91.700,17.500 L 91.700,17.450 L 90.900,17.700 L 89.450,17.900 Q 87.200,17.900 85.900,16.650 Q 84.500,15.300 84.550,13.450 M 87.250,13.450 Q 87.250,14.200 87.800,14.700 Q 88.350,15.150 89.400,15.200 Q 90.400,15.200 91.050,14.700 Q 91.550,14.200 91.550,13.500 Q 91.550,12.600 90.950,11.950 Q 90.300,11.300 89.400,11.350 Q 88.500,11.300 87.900,11.950 Q 87.250,12.550 87.250,13.450 "" />" + Environment.NewLine);
			xw.WriteRaw(@"    </Canvas>" + Environment.NewLine);
			xw.WriteRaw(@"    <VisualBrush x:Key=""v_5"" Visual=""{Binding Source={StaticResource d_5}}"" />" + Environment.NewLine);
		}
		protected void WriteWatermarkStoryboards()
		{
			xw.WriteRaw(Environment.NewLine + @"            <ObjectAnimationUsingKeyFrames Storyboard.TargetName=""i_rt_0"" Storyboard.TargetProperty=""Visibility"" Duration=""0:0:10.333"">" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteObjectKeyFrame KeyTime=""0:0:0"" Value=""{x:Static Visibility.Visible}"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteObjectKeyFrame KeyTime=""0:0:10.2"" Value=""{x:Static Visibility.Hidden}"" />" + Environment.NewLine);
			xw.WriteRaw(@"            </ObjectAnimationUsingKeyFrames>" + Environment.NewLine);
			xw.WriteRaw(@"            <MatrixAnimationUsingKeyFrames Storyboard.TargetName=""i_rt_0"" Storyboard.TargetProperty=""RenderTransform.Matrix"" Duration=""0:0:10.333"">" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:0"" Value=""1 0 0 1 -0.5 -0.5"" />" + Environment.NewLine);
			xw.WriteRaw(@"            </MatrixAnimationUsingKeyFrames>" + Environment.NewLine);
			xw.WriteRaw(@"            <DoubleAnimationUsingKeyFrames Storyboard.TargetName=""i_rt_0"" Storyboard.TargetProperty=""Opacity"" Duration=""0:0:10.333"">" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteDoubleKeyFrame KeyTime=""0:0:0"" Value=""1.000"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteDoubleKeyFrame KeyTime=""0:0:9.6"" Value=""0.895"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteDoubleKeyFrame KeyTime=""0:0:9.666"" Value=""0.789"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteDoubleKeyFrame KeyTime=""0:0:9.733"" Value=""0.684"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteDoubleKeyFrame KeyTime=""0:0:9.8"" Value=""0.578"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteDoubleKeyFrame KeyTime=""0:0:9.866"" Value=""0.473"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteDoubleKeyFrame KeyTime=""0:0:9.933"" Value=""0.367"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteDoubleKeyFrame KeyTime=""0:0:10"" Value=""0.262"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteDoubleKeyFrame KeyTime=""0:0:10.066"" Value=""0.156"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteDoubleKeyFrame KeyTime=""0:0:10.133"" Value=""0.051"" />" + Environment.NewLine);
			xw.WriteRaw(@"            </DoubleAnimationUsingKeyFrames>" + Environment.NewLine);
			xw.WriteRaw(@"            <ObjectAnimationUsingKeyFrames Storyboard.TargetName=""i_rt_1"" Storyboard.TargetProperty=""Visibility"" Duration=""0:0:10.333"">" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteObjectKeyFrame KeyTime=""0:0:0"" Value=""{x:Static Visibility.Hidden}"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteObjectKeyFrame KeyTime=""0:0:5.2"" Value=""{x:Static Visibility.Visible}"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteObjectKeyFrame KeyTime=""0:0:10.2"" Value=""{x:Static Visibility.Hidden}"" />" + Environment.NewLine);
			xw.WriteRaw(@"            </ObjectAnimationUsingKeyFrames>" + Environment.NewLine);
			xw.WriteRaw(@"            <MatrixAnimationUsingKeyFrames Storyboard.TargetName=""i_rt_1"" Storyboard.TargetProperty=""RenderTransform.Matrix"" Duration=""0:0:10.333"">" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:5.2"" Value=""1 0 0 1 2.3 2.2"" />" + Environment.NewLine);
			xw.WriteRaw(@"            </MatrixAnimationUsingKeyFrames>" + Environment.NewLine);
			xw.WriteRaw(@"            <DoubleAnimationUsingKeyFrames Storyboard.TargetName=""i_rt_1"" Storyboard.TargetProperty=""Opacity"" Duration=""0:0:10.333"">" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteDoubleKeyFrame KeyTime=""0:0:5.2"" Value=""1.000"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteDoubleKeyFrame KeyTime=""0:0:9.6"" Value=""0.895"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteDoubleKeyFrame KeyTime=""0:0:9.666"" Value=""0.789"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteDoubleKeyFrame KeyTime=""0:0:9.733"" Value=""0.684"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteDoubleKeyFrame KeyTime=""0:0:9.8"" Value=""0.578"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteDoubleKeyFrame KeyTime=""0:0:9.866"" Value=""0.473"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteDoubleKeyFrame KeyTime=""0:0:9.933"" Value=""0.367"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteDoubleKeyFrame KeyTime=""0:0:10"" Value=""0.262"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteDoubleKeyFrame KeyTime=""0:0:10.066"" Value=""0.156"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteDoubleKeyFrame KeyTime=""0:0:10.133"" Value=""0.051"" />" + Environment.NewLine);
			xw.WriteRaw(@"            </DoubleAnimationUsingKeyFrames>" + Environment.NewLine);
			xw.WriteRaw(@"            <ObjectAnimationUsingKeyFrames Storyboard.TargetName=""i_rt_3"" Storyboard.TargetProperty=""Visibility"" Duration=""0:0:10.333"">" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteObjectKeyFrame KeyTime=""0:0:0"" Value=""{x:Static Visibility.Hidden}"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteObjectKeyFrame KeyTime=""0:0:3.866"" Value=""{x:Static Visibility.Visible}"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteObjectKeyFrame KeyTime=""0:0:5.2"" Value=""{x:Static Visibility.Hidden}"" />" + Environment.NewLine);
			xw.WriteRaw(@"            </ObjectAnimationUsingKeyFrames>" + Environment.NewLine);
			xw.WriteRaw(@"            <MatrixAnimationUsingKeyFrames Storyboard.TargetName=""i_rt_3"" Storyboard.TargetProperty=""RenderTransform.Matrix"" Duration=""0:0:10.333"">" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:3.866"" Value=""1 0 0 1 2.3 -17.8"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:3.933"" Value=""1 0 0 1 2.3 -16.75"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4"" Value=""1 0 0 1 2.3 -15.7"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.066"" Value=""1 0 0 1 2.3 -14.65"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.133"" Value=""1 0 0 1 2.3 -13.6"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.2"" Value=""1 0 0 1 2.3 -12.55"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.266"" Value=""1 0 0 1 2.3 -11.5"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.333"" Value=""1 0 0 1 2.3 -10.45"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.4"" Value=""1 0 0 1 2.3 -9.4"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.466"" Value=""1 0 0 1 2.3 -8.35"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.533"" Value=""1 0 0 1 2.3 -7.25"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.6"" Value=""1 0 0 1 2.3 -6.2"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.666"" Value=""1 0 0 1 2.3 -5.15"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.733"" Value=""1 0 0 1 2.3 -4.1"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.8"" Value=""1 0 0 1 2.3 -3.05"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.866"" Value=""1 0 0 1 2.3 -2"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.933"" Value=""1 0 0 1 2.3 -0.95"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:5"" Value=""1 0 0 1 2.3 0.1"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:5.066"" Value=""1 0 0 1 2.3 1.15"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:5.133"" Value=""1 0 0 1 2.3 2.2"" />" + Environment.NewLine);
			xw.WriteRaw(@"            </MatrixAnimationUsingKeyFrames>" + Environment.NewLine);
			xw.WriteRaw(@"            <ObjectAnimationUsingKeyFrames Storyboard.TargetName=""i_rt_4"" Storyboard.TargetProperty=""Visibility"" Duration=""0:0:10.333"">" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteObjectKeyFrame KeyTime=""0:0:0"" Value=""{x:Static Visibility.Visible}"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteObjectKeyFrame KeyTime=""0:0:5.133"" Value=""{x:Static Visibility.Hidden}"" />" + Environment.NewLine);
			xw.WriteRaw(@"            </ObjectAnimationUsingKeyFrames>" + Environment.NewLine);
			xw.WriteRaw(@"            <MatrixAnimationUsingKeyFrames Storyboard.TargetName=""i_rt_4"" Storyboard.TargetProperty=""RenderTransform.Matrix"" Duration=""0:0:10.333"">" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:0"" Value=""1 0 0 1 115.95 5.95"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:0.066"" Value=""1 0 0 1 102.2 5.95"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:0.133"" Value=""1 0 0 1 88.45 5.95"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:0.2"" Value=""1 0 0 1 74.7 5.95"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:0.266"" Value=""1 0 0 1 60.95 5.95"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:0.333"" Value=""1 0 0 1 47.2 5.95"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:0.4"" Value=""1 0 0 1 33.45 5.95"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:0.466"" Value=""1 0 0 1 19.7 5.95"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:0.533"" Value=""1 0 0 1 5.95 5.95"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.133"" Value=""1 0 0 1 5.95 7.2"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.2"" Value=""1 0 0 1 5.95 8.5"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.266"" Value=""1 0 0 1 5.95 9.75"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.333"" Value=""1 0 0 1 5.95 11"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.4"" Value=""1 0 0 1 5.95 12.3"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.466"" Value=""1 0 0 1 5.95 13.55"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.533"" Value=""1 0 0 1 5.95 14.8"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.6"" Value=""1 0 0 1 5.95 16.1"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.666"" Value=""1 0 0 1 5.95 17.35"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.733"" Value=""1 0 0 1 5.95 18.6"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.8"" Value=""1 0 0 1 5.95 19.9"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.866"" Value=""1 0 0 1 5.95 21.15"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.933"" Value=""1 0 0 1 5.95 22.4"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:5"" Value=""1 0 0 1 5.95 23.7"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:5.066"" Value=""1 0 0 1 5.95 24.95"" />" + Environment.NewLine);
			xw.WriteRaw(@"            </MatrixAnimationUsingKeyFrames>" + Environment.NewLine);
			xw.WriteRaw(@"            <ObjectAnimationUsingKeyFrames Storyboard.TargetName=""i_rt_5"" Storyboard.TargetProperty=""Visibility"" Duration=""0:0:10.333"">" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteObjectKeyFrame KeyTime=""0:0:0"" Value=""{x:Static Visibility.Hidden}"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteObjectKeyFrame KeyTime=""0:0:0.333"" Value=""{x:Static Visibility.Visible}"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteObjectKeyFrame KeyTime=""0:0:5.133"" Value=""{x:Static Visibility.Hidden}"" />" + Environment.NewLine);
			xw.WriteRaw(@"            </ObjectAnimationUsingKeyFrames>" + Environment.NewLine);
			xw.WriteRaw(@"            <MatrixAnimationUsingKeyFrames Storyboard.TargetName=""i_rt_5"" Storyboard.TargetProperty=""RenderTransform.Matrix"" Duration=""0:0:10.333"">" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:0.333"" Value=""1 0 0 1 111.35 6.9"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:0.4"" Value=""1 0 0 1 97.35 6.9"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:0.466"" Value=""1 0 0 1 83.35 6.9"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:0.533"" Value=""1 0 0 1 69.35 6.9"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:0.6"" Value=""1 0 0 1 55.35 6.9"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:0.666"" Value=""1 0 0 1 41.35 6.9"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.133"" Value=""1 0 0 1 41.35 8.15"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.2"" Value=""1 0 0 1 41.35 9.45"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.266"" Value=""1 0 0 1 41.35 10.7"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.333"" Value=""1 0 0 1 41.35 11.95"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.4"" Value=""1 0 0 1 41.35 13.25"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.466"" Value=""1 0 0 1 41.35 14.5"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.533"" Value=""1 0 0 1 41.35 15.75"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.6"" Value=""1 0 0 1 41.35 17.05"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.666"" Value=""1 0 0 1 41.35 18.3"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.733"" Value=""1 0 0 1 41.35 19.55"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.8"" Value=""1 0 0 1 41.35 20.85"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.866"" Value=""1 0 0 1 41.35 22.1"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.933"" Value=""1 0 0 1 41.35 23.35"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:5"" Value=""1 0 0 1 41.35 24.65"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:5.066"" Value=""1 0 0 1 41.35 25.9"" />" + Environment.NewLine);
			xw.WriteRaw(@"            </MatrixAnimationUsingKeyFrames>" + Environment.NewLine);
			xw.WriteRaw(@"            <ObjectAnimationUsingKeyFrames Storyboard.TargetName=""i_rt_6"" Storyboard.TargetProperty=""Visibility"" Duration=""0:0:10.333"">" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteObjectKeyFrame KeyTime=""0:0:0"" Value=""{x:Static Visibility.Hidden}"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteObjectKeyFrame KeyTime=""0:0:0.6"" Value=""{x:Static Visibility.Visible}"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteObjectKeyFrame KeyTime=""0:0:5.133"" Value=""{x:Static Visibility.Hidden}"" />" + Environment.NewLine);
			xw.WriteRaw(@"            </ObjectAnimationUsingKeyFrames>" + Environment.NewLine);
			xw.WriteRaw(@"            <MatrixAnimationUsingKeyFrames Storyboard.TargetName=""i_rt_6"" Storyboard.TargetProperty=""RenderTransform.Matrix"" Duration=""0:0:10.333"">" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:0.6"" Value=""1 0 0 1 110.3 6.25"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:0.666"" Value=""1 0 0 1 102.8 6.25"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:0.733"" Value=""1 0 0 1 95.3 6.25"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:0.8"" Value=""1 0 0 1 87.8 6.25"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:0.866"" Value=""1 0 0 1 80.3 6.25"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:0.933"" Value=""1 0 0 1 72.8 6.25"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:1"" Value=""1 0 0 1 65.3 6.25"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:1.066"" Value=""1 0 0 1 57.8 6.25"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:1.133"" Value=""1 0 0 1 50.3 6.25"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.133"" Value=""1 0 0 1 50.3 7.5"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.2"" Value=""1 0 0 1 50.3 8.8"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.266"" Value=""1 0 0 1 50.3 10.05"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.333"" Value=""1 0 0 1 50.3 11.3"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.4"" Value=""1 0 0 1 50.3 12.6"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.466"" Value=""1 0 0 1 50.3 13.85"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.533"" Value=""1 0 0 1 50.3 15.1"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.6"" Value=""1 0 0 1 50.3 16.4"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.666"" Value=""1 0 0 1 50.3 17.65"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.733"" Value=""1 0 0 1 50.3 18.9"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.8"" Value=""1 0 0 1 50.3 20.2"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.866"" Value=""1 0 0 1 50.3 21.45"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:4.933"" Value=""1 0 0 1 50.3 22.7"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:5"" Value=""1 0 0 1 50.3 24"" />" + Environment.NewLine);
			xw.WriteRaw(@"              <DiscreteMatrixKeyFrame KeyTime=""0:0:5.066"" Value=""1 0 0 1 50.3 25.25"" />" + Environment.NewLine);
			xw.WriteRaw(@"            </MatrixAnimationUsingKeyFrames>" + Environment.NewLine);
		}
		protected void WriteWatermarkInstances()
		{
			int x = (int)v.ViewPort.Size.Width - 110;
			int y = (int)v.ViewPort.Size.Height - 33;
			xw.WriteRaw(Environment.NewLine + @"    <Canvas Canvas.Left=""" + x + @""" Canvas.Top=""" + y + @""">" + Environment.NewLine);
			xw.WriteRaw(@"    <Rectangle x:Name=""i_rt_0"" Fill=""{StaticResource v_1}"" Width=""101"" Height=""24"" RenderTransformOrigin=""0.004950495,0.02083333"" />" + Environment.NewLine);
			xw.WriteRaw(@"    <Rectangle x:Name=""i_rt_1"" Fill=""{StaticResource v_5}"" Width=""95.75"" Height=""17.9"" RenderTransformOrigin=""0,0"" />" + Environment.NewLine);
			xw.WriteRaw(@"    <Canvas x:Name=""i_rt_2"">" + Environment.NewLine);
			xw.WriteRaw(@"      <Canvas.Clip>" + Environment.NewLine);
			xw.WriteRaw(@"        <PathGeometry Figures=""M 0.000,0.000 L 100.000,0.000 L 100.000,23.000 L 0.000,23.000 L 0.000,0.000  Z "" />" + Environment.NewLine);
			xw.WriteRaw(@"      </Canvas.Clip>" + Environment.NewLine);
			xw.WriteRaw(@"      <Rectangle x:Name=""i_rt_3"" Fill=""{StaticResource v_5}"" Width=""95.75"" Height=""17.9"" RenderTransformOrigin=""0,0"" />" + Environment.NewLine);
			xw.WriteRaw(@"      <Rectangle x:Name=""i_rt_4"" Fill=""{StaticResource v_2}"" Width=""32.55"" Height=""11.75"" RenderTransformOrigin=""0,0"" />" + Environment.NewLine);
			xw.WriteRaw(@"      <Rectangle x:Name=""i_rt_5"" Fill=""{StaticResource v_3}"" Width=""7.15"" Height=""10.3"" RenderTransformOrigin=""0,0"" />" + Environment.NewLine);
			xw.WriteRaw(@"      <Rectangle x:Name=""i_rt_6"" Fill=""{StaticResource v_4}"" Width=""44.55"" Height=""11.2"" RenderTransformOrigin=""-0.001122335,-0.004464286"" />" + Environment.NewLine);
			xw.WriteRaw(@"    </Canvas>" + Environment.NewLine);			
			xw.WriteRaw(@"    </Canvas>" + Environment.NewLine);
		}

		static XamlRenderer()
		{
			BuiltInFonts = new List<string>();
			BuiltInFonts.AddRange(
				new string[]
				{
					"Arial", 
					"Arial Black", 
					"Comic Sans", 
					"Comic Sans MS",
					"Courier", 
					"Courier New", 
					"Georgia", 
					"Lucida", 
					"Lucida Sans",
					"LucidaGrande",
					"Lucida Sans Unicode", 
					"Times New Roman", 
					"Trebuchet", 
					"Trebuchet MS", 
					"Verdana", 
					"Webdings"
				}
			);
		}
	}
}




















